package com.telit.firecommand.service.impl;

import com.telit.common.exception.ForestBaseException;
import com.telit.firecommand.dao.FileUploadLogDao;
import com.telit.firecommand.entity.FileUploadLog;
import com.telit.firecommand.service.FileUploadLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * @author zhouyu
 * @description 文件上传日志实现类
 */
@Service
public class FileUploadLogServiceImpl implements FileUploadLogService {

    @Autowired
    private FileUploadLogDao fileUploadLogDao;

    @Override
    public void log(Long fireId, String fileName, String path, Date uploadDate) {
        FileUploadLog fileUploadLog = new FileUploadLog();
        fileUploadLog.setFileName(fileName);
        fileUploadLog.setFilePath(path);
        fileUploadLog.setUploadTime(uploadDate);
        fileUploadLog.setFireId(fireId);
        fileUploadLogDao.insert(fileUploadLog);
    }

    @Override
    public int add(FileUploadLog fileUploadLog) {
        if(fileUploadLog.getFireId() != null  && StringUtils.isBlank(fileUploadLog.getAlarmResource())){
           throw new ForestBaseException("该图片关于火情,所以火情来源不能为空");
        }
        return fileUploadLogDao.insert(fileUploadLog);
    }
}
